package com.ruoyi.combat.repository;

import com.ruoyi.combat.domain.neo4j.OrgNode;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * neo4j org node repository
 * @author baijie
 * @desc: org node repository
 */
@Repository
public interface OrgNodeRepository extends Neo4jRepository<OrgNode, Long>{

    /**
     * 根据组织名称，获取组织信息
     */
    @Query("MATCH (n:org) WHERE n.name = $orgName " +
            "RETURN n")
    OrgNode findOrgNodeByName(@Param("orgName") String orgName);

    /**
     * 根据组织名称，查询不为这个组织名称的组织信息
     */
    @Query("MATCH (n:org) WHERE n.name <> $orgName RETURN n")
    List<OrgNode> findOrgNodeByNotName(@Param("orgName") String orgName);

    @Query(value="MATCH path = (ip:Ip )<-[*1..3]-(o:Org) WHERE ANY(node IN nodes(path) WHERE 'Org' IN labels(node)) and ip.Ip = $ip RETURN o ")
    List<OrgNode> findOrgByIpNew(@Param("ip") String ip);


}
